package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Emp;
import org.example.pojo.EmpQueryParam;
import org.example.pojo.JobOption;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/*
  员工信息
 */
@Mapper
public interface EmpMapper{

//                   传统分页查询
//    /*
//     * 查询总记录数
//     */
//    @Select("select count(*) from emp left join dept on emp.dept_id=dept.id")
//    Long count();
//
//    /*
//     * 分页查询
//     */
//    @Select("select e.*,d.name as deptName from emp e left join dept d on d.id = e.dept_id " +
//            "order by e.update_time desc limit #{start},#{pageSize}")
//    List<Emp> list(Integer start, Integer pageSize);

    //@Select("select e.*,d.name as deptName from emp e left join dept d on d.id = e.dept_id " +
//            "order by e.update_time desc ")
    List<Emp> list(EmpQueryParam param);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp(username,name,gender,phone,job, entry_date,salary,dept_id,create_time,update_time,image) value " +
            "(#{username},#{name},#{gender},#{phone},#{job},#{entryDate},#{salary}, #{deptId},#{createTime},#{updateTime},#{image})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void update(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> getEmpJobData();

    @MapKey("name")
    List<Map<String, Object>> getEmpGenderData();


    @Select("select id, username,name from emp where username=#{username} and password=#{password}")
    Emp login(Emp emp);
}
